{js:my97date}
<div class="headbar">
	<div class="position"><span>工具</span><span>></span><span>广告管理</span><span>></span><span>更新广告</span></div>
</div>
<div class="content_box">
	<div class="content form_content">
		<form action='{url:/tools/ad_edit_act}' method='post' name='ad' enctype='multipart/form-data'>
			<input type='hidden' name='id' value='' />
			<table class="form_table">
				<colgroup>
					<col width="150px" />
					<col />
				</colgroup>
				<tr>
					<th>说明：</th>
					<td>(1)先添加 <广告位> 数据；(2)再添加 <广告> 并且绑定之前添加的 <广告位>，广告数据才可以正常显示 </td>
				</tr>
				<tr>
					<th>名称：</th>
					<td>
						<input type='text' class='normal' name='name' pattern='required' alt="填写名称" />
						<label>*广告名称（必填）</label>
					</td>
				</tr>
				<tr>
					<th>广告展示类型：</th>
					<td>
						<label class='attr'><input type='radio' name='type' value='1' checked=checked />图片</label>
						<label class='attr'><input type='radio' name='type' value='2' />flash</label>
						<label class='attr'><input type='radio' name='type' value='3' />文字</label>
						<label class='attr'><input type='radio' name='type' value='4' />代码</label>

						<div id='ad_box'></div>
					</td>
				</tr>
				<tr>
					<th>广告位：</th>
					<td>
						<select name='position_id' class='normal' pattern='required' alt='广告位不能为空'>
							<option value=''>请选择</option>
							{query:name=ad_position}
							<option value='{$item['id']}'>{$item['name']}</option>
							{/query}
						</select>
						<label>*在选择的广告位置内进行展示（必选）</label>
					</td>
				</tr>
				<tr>
					<th>链接地址：</th>
					<td>
						<input type='text' class='normal' name='link' empty pattern='url' alt='请填写正确URL地址' />
						<label>点击广告后页面链接的URL地址，为空则不跳转</label>
					</td>
				</tr>
				<tr>
					<th>排序：</th>
					<td>
						<input type='text' class='small' name='order' pattern='int' alt='填写正确的数字' />
						<label>数字越小，排列越靠前</label>
					</td>
				</tr>

				<tr>
					<th>开始和结束时间：</th>
					<td>
						<input type='text' class='Wdate' onfocus='WdatePicker()' name='start_time' pattern='date' /> ～
						<input type='text' class='Wdate' onfocus='WdatePicker()' name='end_time' pattern='date' />
						<label>*广告展示的开始时间和结束时间（必选）</label>
					</td>
				</tr>
				<tr>
					<th>描述：</th>
					<td><textarea class='textarea' name='description' alt='请填写文章内容'></textarea></td>
				</tr>
				<tr>
					<th>绑定商品分类：</th>
					<td>
						<!--分类数据显示-->
						<span id="__categoryBox" style="margin-bottom:8px"></span>
						<button class="btn" type="button" name="_goodsCategoryButton"><span class="add">设置分类</span></button>
						{set:plugin::trigger('goodsCategoryWidget',array("name" => "goods_cat_id","value" => isset($this->adRow['goods_cat_id']) ? $this->adRow['goods_cat_id'] : ""))}
						<label> 可选项，与商品分类做关联，与商品分类绑定在一起，动态的展示 </label>
					</td>
				</tr>

				{if:$this->adRow && $this->adRow['position_id']}
				{query:name=ad_position where=id eq $this->adRow['position_id'] item=$positionRow}{/query}
				<tr>
					<th>代码：</th>
					<td style="font-weight:bold;color:#000;font-size:14px;">
						将以下代码Copy到你想要放置广告的任何模板中。 <a href="http://www.aircheng.com/movie" target="_blank">如何添加广告？</a><br />
						<code style="font-weight:normal;font-family:'Courier New';font-size:16px;display:block;background:#333;color:#fff;padding:5px;margin-right:30px;">
							{if:$this->adRow['goods_cat_id']}
							{echo:chr(123)}echo:Ad::show("{$positionRow['name']}",绑定的商品分类ID){echo:chr(125)}
							{else:}
							{echo:chr(123)}echo:Ad::show("{$positionRow['name']}"){echo:chr(125)}
							{/if}
						</code>
					</td>
				</tr>
				{/if}

				<tr>
					<th></th><td><button class='submit' type='submit'><span>确 定</span></button></td>
				</tr>
			</table>
		</form>
	</div>
</div>

<!--广告内容模板-->
<script id="adTemplate" type="text/html">
<%if(newType == "1"){%>
	<input type="file" name="img" class="file" />
	<%if(newType == defaultType){%>
		<p><img src="{webroot:}<%=content%>" width="150px" /></p>
		<input type="hidden" name="content" value="<%=content%>" />
	<%}%>
<%}else if(newType == "2"){%>
	<input type="file" name="flash" class="file" />
	<%if(newType == defaultType){%>
		<embed src="{webroot:}<%=content%>" width="150px" type="application/x-shockwave-flash"></embed>
		<input type="hidden" name="content" value="<%=content%>" />
	<%}%>
<%}else if(newType == "3"){%>
	<input type="text" class="normal" name="content" value="<%=content%>" />
<%}else{%>
	<textarea class='textarea' name='content'><%=content%></textarea>
<%}%>
</script>

<script type='text/javascript'>
//广告数据
defaultAdRow = {echo:JSON::encode($this->adRow)};

//切换广告类型 1:图片; 2:flash; 3:文字; 4:代码;
function changeType(typeVal)
{
	var content = (defaultAdRow && typeVal == defaultAdRow['type']) ? defaultAdRow['content'] : "";
	var defaultType = (defaultAdRow && defaultAdRow['type']) ? defaultAdRow['type'] : "";
	var adHtml = template.render('adTemplate',{'newType':typeVal,'defaultType':defaultType,'content':content});
	$('#ad_box').html(adHtml);
}

//表单回显
var FromObj = new Form('ad');
FromObj.init(defaultAdRow);

//单选按钮点击绑定
$('input:radio[name="type"]').each(
	function(i){
		$(this).bind("click",function()
		{
			changeType(i+1);
		});
	}
);

$("[name='type']:checked").trigger("click");
</script>